package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 护理项目Service实现类
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 护理项目分页条件查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProjectVo> page = nursingProjectMapper.getByPage(name, status);

        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = new PageResponse<>(page);
        // nursingProjectVoPageResponse.setTotal(page.getTotal());
        // nursingProjectVoPageResponse.setPageSize(page.getPageSize());
        // nursingProjectVoPageResponse.setPages((long) page.getPages());
        // nursingProjectVoPageResponse.setPage(page.getPageNum());
        nursingProjectVoPageResponse.setRecords(page.getResult());

        return nursingProjectVoPageResponse;
    }

    /**
     * 添加护理项目
     * @param nursingProjectDto
     */
    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo
    getById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        NursingProjectVo nursingProjectVo = new NursingProjectVo();
        BeanUtils.copyProperties(nursingProject,nursingProjectVo);
        //胡图的做法
        //NursingProjectVo bean = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return nursingProjectVo;
    }

    /**
     * 编辑更新护理项目
     * @param nursingProjectDto
     */
    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDto,nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 启用禁用护理项目
     * @param id
     * @param status
     */
    @Override
    public void enableDisable(Long id, Integer status) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 删除护理项目
     * @param id
     */
    @Override
    public void deleteBuId(Long id) {
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProjectMapper.deleteBuId(nursingProject);
    }


}